<template>
  <div class="login_countain">
    <h3>登录账号</h3>
    <van-form>
      <van-field
        v-model="username"
        name="username"
        label="用户名"
        placeholder="用户名"
        :rules="[{ required: true, message: '请填写用户名' }]"
      />
      <van-field
        v-model="password"
        type="password"
        name="password"
        label="密码"
        placeholder="密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <div style="margin: 16px">
        <p>
          <van-button
            color="linear-gradient(to right, #DC7AE9, #C19BEE,#9EC5F5,#85E4FA)"
            @click="onSubmit"
          >
            登录
          </van-button>
        </p>
      </div>
    </van-form>
    <p>
      <router-link to="/reg"> 还没有账号啊！去注册</router-link>
    </p>
  </div>
</template>
<script>
import { Notify } from 'vant';
import { Toast } from 'vant';
export default {
 components: {
    [Notify.Component.name]: Notify.Component,
  },
  data() {
    return {
      username: "",
      password: "",
      userErr: "用户名不能为空",
      passErr: "密码不能为空",
    };
  },
  methods: {
    onSubmit() {
      if (this.username != 13500000000) {
        Notify({ type: "danger", message: "账号密码错误" });
      } else {
        this.$API
          .getToken({ mobile: this.username, pwd: this.password })
          .then((res) => {
              console.log(res.data.data.token);
            this.$store.commit('token',res.data.data.token)
            this.$router.push("/personage")
            Toast('登录成功');
          });
      }
    },
  },
};
</script>
<style lang="scss">
.login_countain {
  p {
    text-align: center;
    button {
      width: 40%;
    }
  }
}
</style>